/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2024-02-19
 * Time:8:59
 */
public class Solution {
    public int[] runningSum(int[] nums) {
        int[] ret = new int[nums.length];
        ret[0] = nums[0];
        for(int i = 1;i < ret.length;i++) {
            ret[i] = ret[i-1] + nums[i];
        }
        return ret;
    }
    //////////////////////////////////////////////
    //子数组最大平均数
    public static double findMaxAverage(int[] nums, int k) {
        int left = 0,right = 0;
        double sum = 0.0;
        for(;right < k;right++) {
            sum += nums[right];
        }
        right--;
        double aver = sum / k;
        while(right < nums.length-1) {
            sum -= nums[left++];
            sum += nums[++right];
            aver = Math.max(aver,sum/k);
        }
        return aver;
    }
    ///////////////////////////////////////////////////
    //爱生气的书店老板
    public static int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int sum = 0;
        for(int i = 0;i < customers.length;i++) {
            if(grumpy[i] == 0) {
                sum += customers[i];
                customers[i] = 0;
            }
        }
        int left = 0,right = 0,max = 0;
        for(;right < customers.length;right++) {
            sum += customers[right];
            if(right-left+1 > minutes) sum -= customers[left++];
            max = Math.max(max,sum);
        }
         return max;
    }
    /////////////////////////////////////////////////////////
    //寻找数组的中心下标
    public int pivotIndex(int[] nums) {
        int n = nums.length;
        int left = 0,right = n-1;
        int[] arrF = new int[n];
        arrF[0] = 0;
        int[] arrG = new int[n];
        arrG[n-1] = 0;
        for(int i = 1;i < n;i++) {
            arrF[i] = arrF[i-1] +nums[i-1];
        }
        for(int i = n-2;i >= 0;i--) {
            arrG[i] = arrG[i+1] + nums[i+1];
        }

        for(int i = 0;i < n;i++) {
            if(arrF[i] == arrG[i]) return i;
        }
        return -1;
    }



}
